package com.famnote.randomchat;

import java.net.URLEncoder;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;


public class CreateRoomActivity extends Activity implements OnClickListener


{
 // Variable Declaration should be in onCreate()
 private Button mSubmit;
 
 private EditText mRoomTitle;
 private EditText mRoomSubtitle;

 private String mNickname;
 
 //protected DBHelper DB = new DBHelper(Registration.this); 
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  
  
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_create_room);
  
  Bundle b = getIntent().getExtras();
  mNickname = b.getString("nickname");
	
  
  //Assignment of UI fields to the variables
  mSubmit = (Button)findViewById(R.id.submit);
  mSubmit.setOnClickListener(this);
  
  
  mRoomTitle = (EditText)findViewById(R.id.eroomtitle);
  mRoomSubtitle = (EditText)findViewById(R.id.eroomsubtitle);
  
 }

 
 public void onClick(View v) 
 {
  
  switch(v.getId()){
  
  /*
  case R.id.cancel:
   Intent i = new Intent(getBaseContext(), LoginActivity.class);
   startActivity(i);
   //finish();
   break;
   */
  
  case R.id.submit:
   
   
   String roomTitle = mRoomTitle.getText().toString();
   String roomSubtitle = mRoomSubtitle.getText().toString();
   
   
   boolean invalid = false;
      
   if(roomTitle.equals(""))
   {
    invalid = true;
    Toast.makeText(getApplicationContext(), getResources().getString(R.string.notice_room_title), Toast.LENGTH_SHORT).show();
   }
   else
   
   if(roomSubtitle.equals(""))
   {
    invalid = true;
    Toast.makeText(getApplicationContext(), getResources().getString(R.string.notice_room_subtitle), Toast.LENGTH_SHORT).show();
   }
   else
      
	if(invalid == false)
      {
    	  /*
       addEntry(fname, lname, Gen, uname, pass, email);
       Intent i_register = new Intent(this, LoginActivity.class);
       startActivity(i_register);
       //finish();
        */
    	  
    	  finish();
          
            Intent intent = new Intent(this, GroupChat.class);
        	
    		//String room = mProfileid + "@conference.push.appaas.com";
    		//i.putExtra("room", room);
    		
            intent.putExtra("title", roomTitle);
    		
            intent.putExtra("subtitle", roomSubtitle);
    		
    		//String nickName = "hithere";
    		
    		intent.putExtra("nickname", mNickname);
     
    		String bgurl = "";
    		try {
    			bgurl = "http://push.appaas.com/hulbox/display_default.php?"
        			+ "&nickname=" + URLEncoder.encode(mNickname, "utf-8")
        			+ "&title=" + URLEncoder.encode(roomTitle, "utf-8")
        			+ "&subtitle=" + URLEncoder.encode(roomSubtitle, "utf-8");
    		}catch(Exception e){
            	Log.d("downloadUrl",e.toString());
            }    
    		
    		intent.putExtra("bgurl", bgurl);
    		startActivity(intent);
    	  
    	  
    	  
      }
      
      break;
      }
    }
 


 
 
 public void onDestroy()
 {
  super.onDestroy();
  ///DB.close();
 }
 

 
}
